﻿#include "ConstValueNodeGraphicsItem.h"
#include <QPainter>
#include <QLineEdit>
#include <QDebug>
#include "DANodeLinkPointDrawDelegate.h"
ConstValueNodeGraphicsItem::ConstValueNodeGraphicsItem(ConstValueNode* n, QGraphicsItem* p)
    : DA::DAStandardNodeTextGraphicsItem(n, p)
{
    setShowBorder(false);
    setEditable(true);
    setSelectable(true);
    setMovable(true);
    setCurrentValueType(QVariant::String);
    setAutoAdjustSize(false);
    setBodySize(QSize(150, 30));
    getLinkPointDrawDelegate()->showLinkPointText(false);  // 不显示
}

ConstValueNodeGraphicsItem::~ConstValueNodeGraphicsItem()
{
}

void ConstValueNodeGraphicsItem::nodeDisplayNameChanged(const QString& name)
{
}

QVariant::Type ConstValueNodeGraphicsItem::getCurrentValueType() const
{
    return mValueType;
}

void ConstValueNodeGraphicsItem::setCurrentValueType(QVariant::Type v)
{
    switch (v) {
    case QVariant::String:
    case QVariant::Int:
    case QVariant::UInt:
    case QVariant::LongLong:
    case QVariant::ULongLong:
    case QVariant::Double:
    case QVariant::Char:
    case QVariant::Bool: {
        // 生成窗口
    } break;
    default:
        v = QVariant::String;
        break;
    }
    mValueType = v;
}

void ConstValueNodeGraphicsItem::paintBody(QPainter* painter,
                                           const QStyleOptionGraphicsItem* option,
                                           QWidget* widget,
                                           const QRectF& bodyRect)
{
    // 绘制背景
    painter->save();
    painter->setPen(getBorderPen());
    painter->setBrush(getBackgroundBrush());
    painter->drawRoundedRect(bodyRect, mRectRadius, mRectRadius);
    painter->restore();
    //! 绘制连接点
    paintLinkPoints(painter, option, widget);
}

qreal ConstValueNodeGraphicsItem::getRectRadius() const
{
    return mRectRadius;
}

void ConstValueNodeGraphicsItem::setRectRadius(qreal newRectRadius)
{
    if (qFuzzyCompare(mRectRadius, newRectRadius))
        return;
    mRectRadius = newRectRadius;
}
